﻿#include "Heap.h"



void HeapSort(int* a, int n)
{
	//建堆--》时间复杂度是多少？O(N)
	for (int i = (n - 1 - 1) / 2; i>=0;i--)//(n-1)是最后一个元素的下标即最后一个孩子 （n-1-1）/2 求其父亲的下标                   
	{
		AdjustDown(a, n, i);
	}
	int end = n - 1;
	while (end)
	{
		Swap(&a[0], &a[end]);
		AdjustDown(a, end, 0);
		end--;
	}

}

int main()
{
	int a[] = { 15,18,28,34,65,19,49,25,37,27 };
	int n = sizeof(a) / sizeof(a[0]);
	//HeapSort(a, n);
	
	Heap hp;
	HeapInit(&hp, a, n);
	HeapPrint(&hp);

	HeapPush(&hp, 8);
	HeapPrint(&hp);

	HeapPush(&hp, 88);
	HeapPrint(&hp);
	HeapPop(&hp);
	HeapPrint(&hp);
	HeapDestroy(&hp);
	return 0;
}